package com.ceair.flight.refund.service.impl;

import com.ceair.flight.refund.util.BeanCopyUtils;

import com.ceair.muservice.common.dto.AbstractBaseDO;
import com.ceair.muservice.common.dto.BaseReq;
import org.jboss.logging.Logger;

import java.util.Collection;
import java.util.List;

public class BaseServiceImpl<B extends BaseReq,P extends AbstractBaseDO> {

	protected final Logger logger = Logger.getLogger(BaseServiceImpl.class);

	public B trans2Dto(P model, Class<B> clazz) {
		try {
			return (B) BeanCopyUtils.copy(model, clazz);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
			return null;
		}
	}
	
	public Collection<B> trans2Dto(Collection<P> model, Class<B> clazz) {
		try {
			return (List<B>) BeanCopyUtils.copy(model, clazz);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
			return null;
		}
	}

	public P trans2Model(B dto, Class<P> clazz) {
		try {
			return (P) BeanCopyUtils.copy(dto, clazz);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
			return null;
		}
	}

	public Collection<P> trans2Model(Collection<B> dto, Class<P> clazz) {
		try {
			return (List<P>) BeanCopyUtils.copy(dto, clazz);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
			return null;
		}
	}
}
